<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class NotificadorOiController extends AppController {

    var $uses = array('OrdenInspeccion','OrdenTrabajo');
    var $components = array('Cookie');

    function verificarOi() {
        $this->layout = 'ajax';
        $ultimoId = $this->Cookie->read('OrdenInspeccion.id');
        if ($ultimoId == NULL) {
            $ultimoId = 1;
        }
        $lista = $this->OrdenInspeccion->find('all',
                        array('conditions' =>
                            array('OrdenInspeccion.id >' => $ultimoId,
                                'OrdenInspeccion.estado' => '0'),
                            'order' => "OrdenInspeccion.id DESC"));
        if (count($lista)) {
            $ultimo = $this->OrdenInspeccion->find('first',
                            array('conditions' =>
                                array('OrdenInspeccion.id >' => $ultimoId,
                                    'OrdenInspeccion.estado' => '0'),
                                'order' => "OrdenInspeccion.id DESC"));
            $this->Cookie->write('OrdenInspeccion.id', $ultimo["OrdenInspeccion"]["id"], false);
        }
        $this->set(compact('lista'));
    }

    function verificarOt() {
        $this->layout = 'ajax';
        $ultimoId = $this->Cookie->read('OrdenTrabajo.id');
        if ($ultimoId == NULL) {
            $ultimoId = 1;
        }
        $lista = $this->OrdenTrabajo->find('all',
                        array('conditions' =>
                            array('OrdenTrabajo.id >' => $ultimoId,
                                'OrdenTrabajo.estado_id' => '1'),
                            'order' => "OrdenTrabajo.id DESC"));
        if (count($lista)) {
            $ultimo = $this->OrdenTrabajo->find('first',
                            array('conditions' =>
                                array('OrdenTrabajo.id >' => $ultimoId,
                                    'OrdenTrabajo.estado_id' => '1'),
                                'order' => "OrdenTrabajo.id DESC"));
            $this->Cookie->write('OrdenTrabajo.id', $ultimo["OrdenTrabajo"]["id"], false);
        }
        $this->set(compact('lista'));
    }

    function beforeFilter() {
        $this->Cookie->name = 'notificacion';
        $this->Cookie->time = '10 days';
        $this->Cookie->key = 'qSI232qs*&sXOw!';
        $this->Cookie->path = '/';
        //$this->Cookie->domain = 'localhost';
    }

}
?>
